SPB Git
705 B · 10 lines typescript
1import { handler, uuid } from "@/lib/api";2import { updatePage } from "@/lib/pages/service";3/** navigator.sendBeacon target for last-second autosave on page unload (same cookie auth; body is the PATCH payload). */4export const POST = handler(async ({ req, ws, params }) => {5  const id = uuid.parse(params.id); let patch: any = {}; try { patch = JSON.parse(await req.text()); } catch { return Response.json({ ok: false }, { status: 400 }); }6  const allowed: any = {}; for (const k of ["title", "content", "icon", "cover", "properties"]) if (patch[k] !== undefined) allowed[k] = patch[k];7  if (Object.keys(allowed).length) await updatePage(ws.id, id, allowed);8  return Response.json({ ok: true });9});10
Files · main
Menu

Theme